<?php
/*echo $_REQUEST['pro_id'];
echo $_REQUEST['project_name'];
echo $_REQUEST['project_manager'];
echo $_REQUEST['pro_description'];
echo $_REQUEST['start_date'];
echo $_REQUEST['complete_date'];
echo $_REQUEST['pro_status'];*/
include "../../operations/connection_ajax.php";
session_cache_expire(999999999);
if(!isset($_SESSION)) 
{ 
session_start(); 
} 
	if ( !isset($_REQUEST['pages'] ))
		{
	    	$page = 1 ;
		}else{
			$page = $_REQUEST['pages'] ;
	}
	$l_confirm_deleteproject = "Are you sure ?";
	if (isset($_REQUEST['l_confirm_deleteproject'])) $l_confirm_deleteproject = $_REQUEST['l_confirm_deleteproject'];
	$rows_per_page = 15;
	$page_start = ( $page - 1 ) * $rows_per_page; 
	$page_end = $page * $rows_per_page;
	
	$listtestproject=mysql_query("SELECT IDTest from pr_testproject  WHERE IDProject = ".$_REQUEST['pro_id']." and (`Delete` = 0 or `Delete` = 1)");
	echo $listtestproject;
	while ($row = mysql_fetch_array($listtestproject)) {
		mysql_query("DELETE FROM pr_comment WHERE pr_comment.IDTestProject =".$row['IDTest']);
		mysql_query("DELETE FROM pr_logchange WHERE IDTest =".$row['IDTest']);
	}
	
	mysql_query("DELETE FROM pr_testproject WHERE pr_testproject.IDProject =".$_REQUEST['pro_id']);
	
	mysql_query("DELETE FROM pr_composition WHERE IDProject =".$_REQUEST['pro_id']);
	
	mysql_query("DELETE FROM pr_project WHERE IDProject = ".$_REQUEST['pro_id']);
	
	
	$list_projectPage = mysql_query("SELECT p.IDProject FROM pr_project p,employee e WHERE p.IDManager = e.IDEmployee ORDER BY p.IDProject ASC");
	
	$list_project = mysql_query("SELECT p.IDProject,p.IDView, p.NameProject, p.Description,DATE_FORMAT(p.DateStart,'%Y-%m-%d') as DateStart,
 		DATE_FORMAT(p.DateComplete,'%Y-%m-%d') as DateComplete, p.IDManager, p.`Status`, e.FullName 
	        	FROM pr_project p,employee e WHERE p.IDManager = e.IDEmployee ORDER BY p.IDProject ASC limit ".$page_start.",".$rows_per_page);
	
	$number_of_page_projects = ceil ( mysql_num_rows( $list_projectPage ) / $rows_per_page );
	

			$i =0;
			 while ($row=mysql_fetch_array($list_project)){ 
			 		$i++;
                	$indexpage = (($page-1)*15)+$i;
					$pro_id = $row['IDProject'];
					$pro_name =$row['NameProject'];
					$pro_manager =$row['FullName'];
					if ($row['Status']==0) {
						$pro_status = $l_status_project_no;
					}else{
						$pro_status = $l_status_project_done;
					}
					$pro_startdate =$row['DateStart'];
					$pro_completedate =$row['DateComplete'];
				?>
                <tr>
                <td align="center"><?php echo $indexpage;?></td>
                <td align="center"><?php echo $row['IDView'];?></td>
                <td align="center"><a href="project_admin.php?content=admin/project/project-detail.php&id=<?=$pro_id?>"><?php echo $pro_name;?></a></td>  
                <td align="center"><?php echo $pro_manager;?></td>
                <td align="center"><?php echo $pro_status;?></td>
                <td align="center"><?php echo $pro_startdate;?></td>
                <td align="center"><?=$pro_completedate?></td>
                <td align="center">
                	<a href="project_admin.php?content=admin/project/newproject.php&id=<?=$pro_id?>"><span class="buttonProject" style="padding: 5px; border:1px solid #999"><?=$_REQUEST['l_update']?></span></a>
                	<a href="project_admin.php?content=admin/project/project-detail.php&id=<?=$pro_id?>"><span class="buttonProject" style="padding: 5px; border:1px solid #999"><?=$_REQUEST['l_detail']?> </span></a>
                	<span onmouseover="this.style.cursor='pointer'" onmouseout="this.style.cursor='default'" onclick="if(confirm('<?php echo $l_confirm_deleteproject?>')){  ajaxDeleteProject(<?=$pro_id?>)}" class="buttonProject" style="padding: 5px; border:1px solid #999"><?=$_REQUEST['l_delete']?></span>
                	 
                </td>
                </tr>
                <?php }?>
                <tr class="trfoot">
	                    	<td class="rf-dt-ftr-c" scope="colgroup" colspan="8">
	                        	<div style="text-align: center; width: 100%">
	                            	<span class="rf-ds">
															
															<?php if ( $number_of_page_projects > 1 ) 
															{ 
																if ($page==1)
																	$p=2;
																else if ($page==$number_of_page_projects)
																	$p=$number_of_page_projects-1;
																else $p=$page;
																if($page!=1){?>
																	<a onclick="paging(1,'#listproject')" ><span class='button_next'><?php echo "<<<";?></span> </a>
																	<a onclick="paging(<?=($page-1)?>,'#listproject')" ><span class='button_next'><?php echo "<<";?></span> </a>
																<?php  }
																else{
																	echo "<span class='button_next'><<<</span>"; 
																	echo "<span class='button_next'><<</span>";
																}
																for ( $i = $p-1; $i <= $p+1; $i++ ) {	
																		if ($i<=$number_of_page_projects && $i>0)
																		
																			if ($i==$page){
																				echo "<span class='button_next' style='color: #000'><i>".$i."</i></span>"; 
																			}else{
																			?>
																				<a onclick="paging(<?=$i?>,'#listproject')" ><span class="button_next">
																				<?php 
																				echo $i;
																				?>
																				</span> </a>
																			<?php 
																			}
																		?>
																	
																<?php 
																		}
																	
																	if($page!=$number_of_page_projects){ ?>
																		<a onclick="paging(<?=($page+1)?>,'#listproject')"><span class='button_next'><?php echo ">>";?></span> </a>
																		<a onclick="paging(<?=($number_of_page_projects)?>,'#listproject')" ><span class='button_next'><?php echo ">>>";?></span> </a>
																	<?php }
																	else{
																		echo "<span class='button_next'>>></span> ";
																		echo "<span class='button_next'>>>></span> ";
																	}
																}
															
																
																?>
																													
														</span>
														</div>
														</td>
	                    </tr> 

<?php 
mysql_close($connection_ajax);
?>